## -*- coding: utf-8 -*-
<%namespace file="/component/utils.html" import="link, link_for_section" />
<%!
from pythonblog.service.section_service import all_sections, all_types, get_title_by_path
duration_dict = {'recent':u'最近', 'day':u'一天内', 'week':u'一周内', 'month':u'一月内', 'year':u'一年内'}
rank_dict = {'new':u'最新文章', 'hot':u'热点文章', 'total':u'综合排行榜'}
%>
<%def name="nav()">

<%def name="tab(section, curr_section_id)">
<li ${section.id == curr_section_id and "id='active'" or ""}>${link_for_section(section)}</li>
</%def>	

<%
curr_section_id = 0
if c.section_id:
    curr_section_id = int(c.section_id)
%>
<div style="padding-left:40px;padding-top:10px;background-image: url(${h.url_for('/images/nav.jpg')});">
    <ul id="navlist">
        <li \
         % if curr_section_id == 0:
         id='active'\
         % endif
         >${link(h.url_for_home(), u'首页')}</li>
        % for section in all_sections.values():
        ${tab(section, curr_section_id)}
        % endfor
    </ul>
</div>

</%def>

<%def name="logined_header()">
% if h.auth.authorized(h.auth.is_valid_user):
<% userName = request.environ['REMOTE_USER'] %>
<a class="header_link first" href="${h.url_for('home', sub_domain=userName)}"><img height="16" width="16" alt="${userName}" src="${h.url_for('/images/uds.png')}"/> 我的专区</a>
<a class="header_link" href="${h.url_for(controller='post', action='new', sub_domain=userName)}">发表文章</a>
<a class="header_link" href="${h.url_for_www(controller='account', action='log_out', url=h.get_current_url())}">退出</a>
% endif
</%def>

<%def name="header_nav()">
<%def name="sub_section(section)">
<li ${section.path == c.menu.section_path and "class='current'" or ""}><a href="http://${h.home + h.get_path(c.menu, section.path, 1)}"><strong>${section.name}</strong><em> more</em></a></li>
</%def>

<div id="sectionHeader">
    <h1><a href="${h.url_for_home()}">test.com</a></h1>
    % if not h.auth.authorized(h.auth.is_valid_user):
    <a class="header_link first" href="${h.url_for_www(controller='account', action='register')}">加入测试网</a>
    <a class="header_link" id="header-login2" href="#" >发表文章</a>
    <a class="header_link" id="header-login" href="#">登录</a>
    % endif
    <div class="side-header">
        ${logined_header()}
        <form id="search" action="http://www.zhiyiw.cn/search">
            <input type="hidden" name="cx" value="015664028630621552304:8yfip7ejsmk" />
            <input type="hidden" name="cof" value="FORID:9" />
            <input type="hidden" name="ie" value="UTF-8" />
            <input type="text" id="top-keywords" class="inside" name="q" size="31"/>
            <input type="image" id="top-submit" name="sa" alt="Search" src="${h.url_for('/images/search.gif')}"/>
        </form>
        <script type="text/javascript" src="http://www.google.com/coop/cse/brand?lang=zh-Hans"></script>
    </div>
</div>
<div id="sectionMenu">
    <div id="sectionWrapper">
        <div style="float: right; margin-top: 5px; margin-right: 10px;"><img height="23" width="23" alt="rss" src="${h.url_for('/images/rss.gif')}"/></div>
        <ul>
            % if c.menu.section_path != 'all':
            <li class="home"><a href="http://${h.home + h.get_path(c.menu, 'all', 1)}"><strong>全部</strong><em> more</em></a></li>
            % endif
            % for section in all_sections.values():
            ${sub_section(section)}
            % endfor
        </ul>
    </div>
</div>
</%def>

<%def name="header_nav2()">
<%def name="type_url(type)">
%if type.path == c.menu.post_type:
<li class="current"><a class="current" href="http://${h.home + h.get_path(c.menu, type.path, 2)}"><strong>${type.name}</strong></a></li>
%else:
<li><a href="http://${h.home + h.get_path(c.menu, type.path, 2)}"><strong>${type.name}</strong></a></li>
%endif
</%def>

<div id="hotWrapper">
    <div id="hotContainer">
        <div id="featureTabsContainer">
            ${rank_sub_header()}
        </div>
        <ul>
            % if c.menu.post_type != 'all':
            <li><a href="http://${h.home + h.get_path(c.menu, 'all', 2)}"><strong>全部</strong></a></li>
            % endif
            % for type in all_types.values():
            ${type_url(type)}
            % endfor
        </ul>
    </div>
</div>
</%def>

<%def name="header_blog()">
<div id="sectionHeader">
    <a class="header_link first" href="${h.url_for_home()}">首页</a>
    % if not h.auth.authorized(h.auth.is_valid_user):
    <a class="header_link" href="${h.url_for_www(controller='account', action='register')}">加入测试网</a>
    <a class="header_link" id="header-login" href="#">登录</a>
    % endif
    <div class="side-header" style="padding-right: 10px;">
        ${logined_header()}
    </div>
</div>
</%def>

<%def name="rank_extra_lable(name, title=None)">
    <div id="hotWrapper">
        <div id="hotContainer">
            <div id="featureTabsContainer">
                ${rank_sub_header(1)}
                <a href="javascript:" class="menu tab tab_selected rounded {top transparent}"><span style="font-weight:bold;" title="${title}">${name}</span></a>
            </div>
        </div>
    </div>
</%def>

<%def name="rank_sub_header(extra=0)">
    <%def name="rank_url(rank, extra)">
    <a href="http://${h.home + h.get_path(c.menu, rank, 3)}" class="menu tab ${(c.menu.rank_type==rank and extra==0) and 'tab_selected' or ''} rounded {top transparent}"><span style="font-weight:bold;">${rank_dict[rank]}</span></a>
    </%def>
    ${rank_url('new', extra)}
    ${rank_url('hot', extra)}
    ${rank_url('total', extra)}
</%def>

<%def name="selector()">
    <%def name="select(duration)">
        %if duration != c.menu.time_duration:
        <a class="tool" href="http://${h.home + h.get_path(c.menu, duration, 4)}">${duration_dict[duration]}</a>
        %endif
    </%def>
    <div class="selector">
        ${select('year')}
        ${select('month')}
        ${select('week')}
        ${select('day')}
        ${select('recent')}
        <span class="tool"><strong>${duration_dict[c.menu.time_duration]}</strong></span>
        <h2> ${get_title_by_path(c.menu.section_path)} </h2>
    </div>
</%def>
